rm(list =ls())
options(scipen=999)
gc()
packages <-c("tidyverse","estimatr","plm","stargazer",
             "fastDummies","ICCbin","ihs","readstata13","xtable")

new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

lapply(packages, require, character.only = TRUE)
rm(packages, new.packages)

setwd("PUT YOUR DIRECTORY HERE")

# load data
data <- read.csv("./Datasets/main_confounders.csv")


# rearrange data and scale
data <- data%>%
  dplyr::rowwise()%>%
  dplyr::mutate(commander_1975_79 = mean(c(commanders1975, commanders1976, 
                                           commanders1977, commanders1978,
                                           commanders1979), na.rm = TRUE))%>%
  dplyr::ungroup()

# run models
lm_strikes <- lm(strikes_1970 ~ commander_1975_79, data = data)

# save as tex
stargazer(lm_strikes,
          dep.var.labels = c("Protests in the 1970s"),
          style = "qje",
          covariate.labels = c("Surveilance"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01),
          omit = c("Constant", "factor"),
          omit.stat = c("rsq", "f", "ser"), 
          omit.table.layout = "n",
          add.lines = list(c("Fixed effects", "No"),
                           c("Controls", "No")),
          out = "PUT YOUR FILEPATH HERE")
